<template>
	<view>
		<image class="baiduImg" src="../../static/baidu.png" mode="aspectFit"></image>
		<SearchInput2 @publish="onPublish" :lists="lists" ></SearchInput2>
		<!-- <HotList :lists="lists" @del="onDel"></HotList> -->
	</view>
</template>

<script setup>
	
	import {
		ref
	} from 'vue';
	import {
		onPageScroll
	} from '@dcloudio/uni-app';
	const lists = ref([{
			id: 111,
			title: "刚满18岁"
		},
		{
			id: 222,
			title: "我不吃牛肉"
		},
		{
			id: 333,
			title: "遥遥领先"
		},
		{
			id: 444,
			title: "哪里贵了"
		}
	])
	
	
	function onPublish(e) {
		const existingIndex = lists.value.findIndex(item => item.title === e);
		if (existingIndex !== -1) {
			// 如果存在相同的元素，则先从列表中删除
			const existingItem = lists.value.splice(existingIndex, 1)[0];
			// 将存在的元素放到列表的最前面
			lists.value.unshift(existingItem);
		}else{
			lists.value.unshift({
				id: Date.now(),
				title: e
			});
		}
	}
	
	const rollValue = ref(0)
	
	onPageScroll((e) => {
		rollValue.value = e.scrollTop
	})
	
	function goTop() {
		uni.pageScrollTo({
			scrollTop: 0, // 滚动到顶部
			duration: 300 // 滚动动画持续时间，单位 ms
		});
	}
	
	function onDel(){
		
	}
</script>
	
<style lang="scss" scoped>
	.baiduImg{
		width: 350rpx;
		margin-left: 200rpx;
		height: 200rpx;
	}

</style>
